/*
 * Copyright (c) 2023-2025 elsfs Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.elsfs.cloud.common.mybatis.ext.db;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.DeleteSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.InsertSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.QueryListSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.QueryOneSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.QueryPageSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.UnionSqlExecutor;
import org.elsfs.cloud.common.mybatis.ext.sql.support.executor.UpdateSqlExecutor;

/** VEF SQL执行器工厂实现 */
@RequiredArgsConstructor
public class VefSqlExecutorFactory implements SqlExecutorFactory {

  /** 通用SQL执行器 */
  private final GenericSqlExecutor genericSqlExecutor;

  /**
   * 查询单条数据
   *
   * @param clazz 数据项类
   * @return SQL执行器
   */
  @Override
  public <R> QueryOneSqlExecutor<R> queryOne(Class<R> clazz) {
    return new QueryOneSqlExecutor<>(this.genericSqlExecutor, clazz);
  }

  /**
   * 查询列表数据
   *
   * @param clazz 数据项类
   * @return SQL执行器
   */
  @Override
  public <R> QueryListSqlExecutor<R> queryList(Class<R> clazz) {
    return new QueryListSqlExecutor<>(this.genericSqlExecutor, clazz);
  }

  /**
   * 查询分页数据
   *
   * @param pageable 分页对象
   * @param clazz 数据项类
   * @return SQL执行器
   */
  @Override
  public <R> QueryPageSqlExecutor<R> queryPage(IPage<R> pageable, Class<R> clazz) {
    return new QueryPageSqlExecutor<>(this.genericSqlExecutor, pageable, clazz);
  }

  /**
   * 联合数据查询
   *
   * @param clazz 数据项类
   * @return SQL执行器
   */
  @Override
  public <R> UnionSqlExecutor<R> unionQuery(Class<R> clazz) {
    return new UnionSqlExecutor<>(this.genericSqlExecutor, clazz);
  }

  /**
   * 插入数据
   *
   * @return SQL执行器
   */
  @Override
  public InsertSqlExecutor insert() {
    return new InsertSqlExecutor(this.genericSqlExecutor);
  }

  /**
   * 更新数据
   *
   * @return SQL执行器
   */
  @Override
  public UpdateSqlExecutor update() {
    return new UpdateSqlExecutor(this.genericSqlExecutor);
  }

  /**
   * 删除数据
   *
   * @return SQL执行器
   */
  @Override
  public DeleteSqlExecutor delete() {
    return new DeleteSqlExecutor(this.genericSqlExecutor);
  }
}
